<template>
  <div class="table-wrap">
    <div class="search_header">
      <div></div>
      <div class="search_header_right">
        <el-select
          placeholder="项目分类"
          v-model="parameter.projectType"
          clearable
          @change="search"
        >
          <el-option
            v-for="item in projectTypeOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
        <el-select
          placeholder="四大结构调整"
          v-model="parameter.projectSdjg"
          clearable
          @change="search"
        >
          <el-option
            v-for="item in projectStructOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
        <el-select
          placeholder="细分类型"
          v-model="parameter.xflx"
          clearable
          @change="search"
        >
          <el-option
            v-for="item in projectDivisionOptions"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
        <el-select
          placeholder="审核状态"
          v-model="parameter.checkStatus"
          clearable
          @change="search"
        >
          <el-option
            v-for="item in checkStatusList"
            :key="item.value"
            :label="item.label"
            :value="item.value"
          >
          </el-option>
        </el-select>
        <el-input
          placeholder="  请输入项目名称"
          v-model="parameter.keyWord"
          clearable
        >
          <span
            @click="search"
            slot="suffix"
            style="display: inline-block"
          >
            <Icon
              title="搜索"
              name="sousuo"
              color="#A7ADB5"
              font-size="20"
            />
          </span>
        </el-input>
      </div>
    </div>
    <el-table
      :data="userList"
      :header-cell-style="{
        background: '#F2F6FB ',
        color: ' #6B767D'
      }"
      :row-class-name="tableRowClassName"
      v-loading="loading"
    >
      <el-table-column
        label="序号"
        show-overflow-tooltip
        width="80"
        align="center"
      >
        <template slot-scope="scope">
          {{ scope.$index + 1 }}
        </template>
      </el-table-column>
      <el-table-column
        label="项目编号"
        prop="projectNo"
        show-overflow-tooltip
      />
      <el-table-column
        label="项目分类"
        prop="projectTypeText"
        show-overflow-tooltip
      />
      <el-table-column
        label="项目名称"
        prop="projectName"
        show-overflow-tooltip
      />
      <el-table-column
        label="四大结构调整"
        prop="projectSdjgText"
        show-overflow-tooltip
      />
      <el-table-column
        label="细分类型"
        prop="xflxText"
        show-overflow-tooltip
      />
      <!-- <el-table-column
          label="建设规模"
          prop="createTime"
          show-overflow-tooltip
        /> -->
      <el-table-column
        label="建设周期"
        prop="jszq"
        show-overflow-tooltip
      >
        <template v-slot="scope">
          {{
            !scope.row.jszq || scope.row.jszq == ''
              ? scope.row.jszq
              : JSON.parse(scope.row.jszq)[0] +
                '-' +
                JSON.parse(scope.row.jszq)[1]
          }}
        </template>
      </el-table-column>
      <el-table-column
        label="更新时间"
        prop="xmjsTime"
        show-overflow-tooltip
      />
      <el-table-column
        label="项目状态"
        prop="projectStatus"
        show-overflow-tooltip
      >
        <template v-slot="scope">
          <!-- {{ mapStatusName(scope.row.xmjsStatus) }} -->
          {{ scope.row.projectStatusText }}
        </template>
      </el-table-column>
      <el-table-column
        label="审核状态"
        prop="xmjsStatus"
        show-overflow-tooltip
      >
        <template v-slot="scope">
          <!-- {{ mapStatusName(scope.row.xmjsStatus) }} -->
          {{ scope.row.xmjsStatusText }}
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        show-overflow-tooltip
        min-width="120"
      >
        <!-- 待审核不能编辑，非管理员用户（企业客户）在项目已完成状态且流程审核通过不能编辑 -->
        <template v-slot="scope">
          <el-button
            type="text"
            style="color: #00baff; font-weight: 400"
            v-if="
              scope.row.xmjsStatus !== 1 && isAdminUser
                ? true
                : scope.row.projectStatus !== '1' &&
                  scope.row.xmjsStatus !== 1 &&
                  $filterGlobalPermission(
                    'projectSettlement:edit'
                  )
            "
            @click="handleDetail(4, scope, 'edit')"
            >{{ isAdminUser ? '编辑' : '填报' }}
          </el-button>
          <el-button
            type="text"
            style="color: #00baff; font-weight: 400"
            v-if="
              scope.row.xmjsStatus == 1 &&
              isAdminUser &&
              $filterGlobalPermission(
                'projectSettlement:check'
              )
            "
            @click="handleDetail(4, scope, 'shenhe')"
            >审核
          </el-button>
          <el-button
            type="text"
            style="color: #00baff; font-weight: 400"
            @click="handleDetail(4, scope, 'detail')"
            >查看</el-button
          >
          <el-button
            type="text"
            style="color: #ff0000; font-weight: 400"
            v-if="
              scope.row.xmjsStatus == 2 &&
              isAdminUser &&
              $filterGlobalPermission(
                'projectSettlement:back'
              )
            "
            @click="handleTuiHui(scope)"
            >退回</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <div class="table-pagination" v-if="total">
      <el-pagination
        background
        layout="prev, pager, next"
        :page-size="parameter.pageSize"
        @current-change="pageChange"
        :total="total"
      >
      </el-pagination>
    </div>
    <tuihui ref="tuihui" @forceRender="getList"></tuihui>
  </div>
</template>

<script>
import { userQuery } from '@/api/user'
import { getProjectRecordList } from '@/api/projectRecord'
import { mixin } from '../projectMethods'
import Icon from '@/components/icon'
import { queryOptions } from '@/api/dict'
import tuihui from '../component/tuihui.vue'
import { isAdmin } from '@/utils/permission/index'
export default {
  name: 'index',
  components: {
    Icon,
    tuihui
  },
  mixins: [mixin],
  data() {
    return {
      loading: false,
      userList: [],
      total: '',
      parameter: {
        projectType: '',
        projectSdjg: '',
        xflx: '',
        checkStatus: '',
        stage: 'xmjs',
        keyword: '',
        pageIndex: 1,
        pageSize: 10
      },
      roleOptions: [],
      // checkStatusList: [
      //   { label: '待提交', value: 0 },
      //   { label: '待审核', value: 1 },
      //   { label: '审核通过', value: 2 },
      //   { label: '审核退回', value: 3 }
      // ],
      projectTypeOptions: [], // 项目分类
      projectStructOptions: [], // 四大结构调整
      projectDivisionOptions: [], // 细分类型
      checkStatusList: [], // 审核状态
      projectStatusOptions: [], // 项目状态
      projectList: [],
      total: '',
      isAdminUser: null
    }
  },
  computed: {},
  async created() {
    await this.getTypeOptions()
    await this.getStructOptions()
    await this.getDivisionOptions()
    await this.getStatusOptions()
    this.isAdminUser = isAdmin()
  },
  mounted() {
    this.getList()
    this.isAdminUser = isAdmin()
  },
  methods: {
    // 获取用户列表
    // getList() {
    //   queryProjectList(this.parameter).then((res) => {
    //     if (res.success) {
    //       this.total = res.data.count
    //       this.projectList = res.data.list.map((item) => {
    //         return {
    //           ...item,
    //           projectTypeText:
    //             this.projectTypeOptions.filter(
    //               (i) => i.value === item.projectType
    //             )[0]?.label,
    //           projectSdjgText:
    //             this.projectStructOptions.filter(
    //               (i) => i.value === item.projectSdjg
    //             )[0]?.label,
    //           xflxText: this.projectDivisionOptions.filter(
    //             (i) => i.value === item.xflx
    //           )[0]?.label,
    //           projectStatusText:
    //             this.projectStatusOptions.filter(
    //               (i) => i.value === item.projectStatus
    //             )[0]?.label,
    //           bpmStatusText:
    //             this.projectCheckOptions.filter(
    //               (i) => i.value === item.bpmStatus
    //             )[0]?.label
    //           // jszqText: JSON.parse(item.jszq)
    //         }
    //       })
    //     }
    //   })
    // },
    // 项目分类
    getTypeOptions() {
      queryOptions('projectType').then((res) => {
        if (res.success) {
          this.projectTypeOptions = res.data.map((item) => {
            return {
              label: item.dictText,
              value: item.dictValue
            }
          })
        }
      })
    },

    // 四大结构调整
    getStructOptions() {
      queryOptions('projectSdjg').then((res) => {
        this.projectStructOptions = res.data.map((item) => {
          return {
            label: item.dictText,
            value: item.dictValue
          }
        })
      })
    },

    // 细分类型
    getDivisionOptions() {
      queryOptions('xflx').then((res) => {
        this.projectDivisionOptions = res.data.map(
          (item) => {
            return {
              label: item.dictText,
              value: item.dictValue
            }
          }
        )
      })
    },
    // 审核状态
    getStatusOptions() {
      queryOptions('clshzt').then((res) => {
        this.checkStatusList = res.data.map((item) => {
          return {
            label: item.dictText,
            value: item.dictValue
          }
        })
      })
    },
    search() {
      console.log(this.parameter, 'par')
      // this.parameter.pageIndex = 1
      this.total = ''
      // if (Array.isArray(this.parameter.deptId)) {
      //   this.parameter.deptId =
      //     this.parameter.deptId[
      //       this.parameter.deptId.length - 1
      //     ]
      // }
      this.getList()
    },
    // pageChange
    pageChange(page) {
      this.parameter.pageIndex = page
      this.getList()
    },
    // 获取用户列表
    getList() {
      this.loading = true
      getProjectRecordList(this.parameter).then((res) => {
        if (res.success) {
          this.userList = res.data.list
          this.total = res.data.count
        } else {
          this.$message.error(res.message)
        }
        this.loading = false
      })
    },
    // tanble row
    tableRowClassName({ rowIndex }) {
      if (rowIndex % 2 === 1) {
        return 'light'
      } else {
        return ''
      }
    },
    handleTuiHui(scope) {
      console.log(scope.row)
      this.$refs.tuihui.changeDialog(
        scope.row,
        this.parameter.stage
      )
    }
  }
}
</script>

<style scoped lang="scss">
@import '~@/assets/css/table.scss';
</style>
